package com.norbitltd.guavaleaves.java.lang;

import com.google.common.base.Predicate;

public class DoublePredicates {
	/**
	 * Returns a predicate which checks whether the predicate argument is
	 * greater than a given double value
	 * 
	 * @param d
	 *            Value to compare the predicate value with
	 * @return True if the predicate value is greater than d, false otherwise
	 */
	public static Predicate<Double> isGreaterThan(final double d) {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input > d;
			}
		};
	}

	/**
	 * Returns a predicate which checks whether the predicate argument is
	 * greater than or equal to a given double value
	 * 
	 * @param d
	 *            Value to compare the predicate value with
	 * @return True if the predicate value is greater than or equal to d, false
	 *         otherwise
	 */
	public static Predicate<Double> isGreaterOrEqualThan(final double d) {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input >= d;
			}
		};
	}

	/**
	 * Returns a predicate which checks whether the predicate argument is lower
	 * than a given double value
	 * 
	 * @param d
	 *            Value to compare the predicate value with
	 * @return True if the predicate value is lower than d, false otherwise
	 */
	public static Predicate<Double> isLowerThan(final double d) {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input < d;
			}
		};
	}

	/**
	 * Returns a predicate which checks whether the predicate argument is lower
	 * that or equal to than a given double value
	 * 
	 * @param d
	 *            Value to compare the predicate value with
	 * @return True if the predicate value is lower than or equal to d, false
	 *         otherwise
	 */
	public static Predicate<Double> isLowerOrEqualThan(final double d) {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input <= d;
			}
		};
	}

	/**
	 * Returns a predicate which check whether the predicate argument is equal
	 * to a given int value
	 * 
	 * @param d
	 *            Value to compare the predicate value with
	 * @return True if the predicate value is equal to d, false otherwise
	 */
	public static Predicate<Double> isEqual(final double d) {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input == d;
			}
		};
	}

	/**
	 * Returns a predicate which check whether the predicate argument is not
	 * equal to a given int value
	 * 
	 * @param d
	 *            Value to compare the predicate value with
	 * @return True if the predicate value is not equal to d, false otherwise
	 */
	public static Predicate<Double> isNotEqual(final double d) {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input != d;
			}
		};
	}

	/**
	 * Returns a predicate which check whether the predicate argument is a
	 * positive int value
	 * 
	 * @return True if the predicate value is greater than 0, false otherwise
	 */
	public static Predicate<Double> isPositive() {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input > 0;
			}
		};
	}

	/**
	 * Returns a predicate which check whether the predicate argument is a
	 * negative int value
	 * 
	 * @return True if the predicate value is lower than 0, false otherwise
	 */
	public static Predicate<Double> isNegative() {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input < 0;
			}
		};
	}

	/**
	 * Returns a predicate which check whether the predicate argument is a
	 * zero-valued int value
	 * 
	 * @return True if the predicate value is equal 0, false otherwise
	 */
	public static Predicate<Double> isZero() {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input == 0;
			}
		};
	}

	/**
	 * Returns a predicate which check whether the predicate argument is not a
	 * zero-valued int value
	 * 
	 * @return True if the predicate value is not equal 0, false otherwise
	 */
	public static Predicate<Double> isNotZero() {
		return new Predicate<Double>() {
			public boolean apply(Double input) {
				return input != null && input != 0;
			}
		};
	}
}
